home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / LIBRARY / PAS_0493 / TOMPKTS.PAS < prev    next >
Pascal/Delphi Source File  |  1993-04-15  |  2KB  |  61 lines

  1. {─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
  2. Msg  : 357 of 367
  3. From : Tom Lawrence                        1:2605/606.0         11 Apr 93  23:56
  4. To   : Andrew Fort
  5. Subj : Data structures
  6. ────────────────────────────────────────────────────────────────────────────────
  7.  > Yep, you people out there may notice that in fact this is an extended
  8.  > fidonet type-2 mail packet packed message header.. I know you cannot
  9.  > just blockread this, since the DateTime/ToName/FromName/Subject
  10.  > fields are null-terminated, so how do I do it?
  11.  
  12.     I usually Blockread the header up to the To field (the Date is null
  13. terminated, but it's always 20 characters).  Then, Blockread in the 36
  14. characters for the To field, look for the #0, and move the file pointer back..
  15. for example, suppose you blockread in 36 bytes, and the 0 was at the 17th
  16. cell...  36-17=19, so you'd move the file pointer back 19 bytes
  17. (Seek(F),FilePos(F)-19), then do the same thing with the From field, then the
  18. subject.  Or, if you want, Blockread 144 bytes into a buffer, extract each
  19. string, and seek back in the file only once.  StrTok is a handy function to use
  20. for this, taken from C's StrTok function...  here's some sample code: }
  21.  
  22. {********************************************************************}
  23. Function StrTok(Var S:String;Tokens:String):String;
  24. Var X,
  25.     Y,
  26.     Min:Byte;
  27.     T:String;
  28. Begin
  29.     While Pos(S[1],Tokens)>0 Do
  30.     Begin
  31.         Delete(S,1,1);
  32.         If S='' Then Exit;
  33.     End;
  34.     Min:=Length(S);
  35.     For X:=1 to Length(Tokens) Do
  36.     Begin
  37.         Y:=Pos(Tokens[X],S);
  38.         If (Y>0) and (Y<Min) Then Min:=Y;
  39.     End;
  40.  
  41.     If Min<Length(S) Then T:=Copy(S,1,Min-1)
  42.         Else T:=Copy(S,1,Min);
  43.     Delete(S,1,Min);
  44.     If Pos(T[Length(T)],Tokens)>0 Then Dec(T[0]);
  45.     StrTok:=T;
  46. End;
  47. {********************************************************************}
  48. Var F:File;
  49.     S:String;
  50.     BytesRead:Word;
  51. Begin
  52.     {* Assuming F is assigned to the message, opened, and you've
  53.        already read up to and including the Data field *}
  54.     BlockRead(F,S[1],144,BytesRead);
  55.     S[0]:=Char(Lo(BytesRead));
  56.     Message_To:=StrTok(S,#0);
  57.     Message_From:=StrTok(S,#0);
  58.     Message_Subject:=StrTok(S,#0);
  59.     Seek(F,FilePos(F)-(BytesRead-(Length(Message_To)+Length(Message_From)
  60.          +Length(Message_Subject))));
  61. End.